<template>
	<view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #e64340;">&#xe611;</text>教师编号</view>
			<view class="input-content">
				<input class="text-input" type="text" disabled v-model="tid" />
			</view>
		</view>

		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #4edfe6;">&#xebe4;</text>操作类型</view>
			<view class="input-content">
				<picker @change="optionTypeIndex=$event.detail.value" :value="optionTypeIndex" :range="optionType">
					<text>{{optionType[optionTypeIndex]}}</text>
				</picker>
			</view>
		</view>
		
		<view class="input-item" v-if="optionTypeIndex!=0">
			<view class="title"><text class="iconfont" style="color: #801ae6;">&#xe7cb;</text>团队编号</view>
			<view class="input-content">
				<input class="text-input" type="text" v-model="teaTeamId" />
			</view>
		</view>

		<view class="textarea">
			<textarea placeholder="请输入变更理由" v-model="con" />
			</view>
		<view class="bottom">
			<button type="primary" @click="submit"><text class="iconfont" style="color: #FFFFFF;">&#xe64a;</text>提交</button>
		</view>
	</view>
</template>
<script>
	import 	{apply,applyEdit,applyDel,delTeamApply} from '@/api/tTeam.js'
	
	function timeFormat() {
		const date = new Date()
		let year = date.getFullYear()
		let month = date.getMonth() + 1
		let day = date.getDate()
		let hour = date.getHours()
		let min = date.getMinutes()
		let second = date.getSeconds()
		month = month > 9 ? month : '0' + month
		day = day > 9 ? day : '0' + day;
		hour = hour > 9 ? hour : '0' + hour;
		min = min > 9 ? min : '0' + min;
		second = second > 9 ? second : '0' + second;
		return `${year}-${month}-${day} ${hour}:${min}:${second}`
	}
	
	export default {
		data() {
			return {
				tid:getApp().globalData.tid,
				optionType:['新增','修改','删除'],
				optionTypeIndex:0,
				con: '',
				teaTeamId:''
			}
		},
		methods: {
			submit:function(){
				switch(this.optionTypeIndex){
					case 0:{
						apply({
							teaTeamId:this.teaTeamId,
							tid:this.tid,
							con:this.con,
							time:timeFormat(),
							type:this.optionTypeIndex
						}).then(res=>{
							if(res.data.code==0){
								uni.showModal({
									content:'提交成功',
									complete() {
										uni.navigateBack()
									}
								})
							}else{
								uni.showModal({
									content:'提交失败'
								})
							}
						}).catch(err=>{
							uni.showModal({
								content:'请求失败'
							})
						})
						break
					}
					case 1:{
						applyEdit({
							teaTeamId:this.teaTeamId,
							tid:this.tid,
							con:this.con,
							time:timeFormat(),
							type:this.optionTypeIndex
						}).then(res=>{
							if(res.data.code==0){
								uni.showModal({
									content:'提交成功',
									complete() {
										uni.navigateBack()
									}
								})
							}else{
								uni.showModal({
									content:'提交失败'
								})
							}
						}).catch(err=>{
							uni.showModal({
								content:'请求失败'
							})
						})
						break
					}
					case 2:{
						applyDel({
							teaTeamId:this.teaTeamId,
							tid:this.tid,
							con:this.con,
							time:timeFormat(),
							type:this.optionTypeIndex
						}).then(res=>{
							if(res.data.code==0){
								uni.showModal({
									content:'提交成功',
									complete() {
										uni.navigateBack()
									}
								})
							}else{
								uni.showModal({
									content:'提交失败'
								})
							}
						}).catch(err=>{
							uni.showModal({
								content:'请求失败'
							})
						})
						break
					}
				}
			}
		}
	}
</script>

<style>
	page{
		font-family: 'Courier New', Courier, monospace;
	}
	.iconfont {
		font-family: "iconfont" !important;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		/* color: #C0C0C0; */
		font-size: 20px;
		margin-right: 5px;
		color: #e64340;
	}
	.input-item {
		height: auto;
		position: relative;
		height: 40px;
		margin: 0 5px;
		border-bottom: 1px solid #C0C0C0;
	}

	.input-item .title {
		position: absolute;
		top: 0;
		left: 0;
		width: 30%;
		height: 100%;
		text-align: center;
		line-height: 40px;
	}

	.input-item .input-content {
		position: absolute;
		top: 0;
		right: 0;
		width: 70%;
		height: 100%;
	}

	.input-item .input-content .text-input {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
	picker{
		margin-top: 5px;
	}
	
	.textarea{
		margin-top: 15px;
		padding: 0 10px;
		height: 150px;
	}
	.textarea textarea{
		width: 95%;
		border-radius: 10px;
		border: 1px solid #808080;
		padding: 5px 10px;
	}
	.bottom{
		margin-top: 30px;
		padding: 0 10px;
	}
	
</style>
